home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / ANSI.ASM < prev    next >
Assembly Source File  |  1992-01-24  |  14KB  |  432 lines

  1. ; this is ripped off from pd code in RBBS-ASM (was ANSI1-7.ASM)
  2. ; has been heavily modified by M. Kimes, who isn't much of an
  3. ; asm-programmer.  Now works with C in a strange way and supports
  4. ; configurable window.  It's momma wouldn't know it now (and probably
  5. ; would claim it's the type of program she warned it about).
  6. ; I reckon it was public domain before, and still is.
  7. ;
  8. ; int  far pascal ansi      (char far *str);
  9. ; void far pascal setcoords (int topx,int topy,int botx,int boty);
  10. ; void far pascal getcoords (int far *topx,int far *topy,int far *botx,int far *boty);
  11. ; void far pascal setfastansi (int fast);
  12. ;
  13.  
  14. .model large
  15.  
  16. ANSI_PRNT SEGMENT PUBLIC 'CODE'
  17.           ASSUME CS:ANSI_PRNT
  18.           PUBLIC ANSI,SETCOORDS,GETCOORDS,SETFASTANSI,GETFASTANSI
  19.           PUBLIC _atop,_atopy,_atopx,_abot,_aboty,_abotx,_fastansiout
  20.  
  21. VID_PAGE          DB 0                  ;Active video page
  22. _atop             LABEL WORD
  23. _atopy            DB 0                  ;top y coord
  24. _atopx            DB 0                  ;top x coord
  25. _abot             LABEL WORD
  26. _aboty            DB 17h                ;bottom y coord
  27. _abotx            DB 4Fh                ;bottom x coord
  28. _fastansiout      DB 1                  ;fast ansi writes?
  29.  
  30.  
  31. GETCOORDS PROC    FAR   ;void pascal far getcoords(int *topx,int *topy,
  32.                         ;                          int *botx,int *boty);
  33.  
  34. ; get window coordinates (0 based)
  35.  
  36.           PUSH    BP
  37.           MOV     BP,SP
  38.           PUSH    DS
  39.           MOV     AH,0
  40.           MOV     AL,_atopx
  41.           MOV     BX,[BP]+18
  42.           MOV     DS,[BP]+20
  43.           MOV     [BX],AX
  44.           MOV     AL,_atopy
  45.           MOV     DS,[BP]+16
  46.           MOV     BX,[BP]+14
  47.           MOV     [BX],AX
  48.           MOV     AL,_abotx
  49.           MOV     DS,[BP]+12
  50.           MOV     BX,[BP]+10
  51.           MOV     [BX],AX
  52.           MOV     AL,_aboty
  53.           MOV     DS,[BP]+8
  54.           MOV     BX,[BP]+6
  55.           MOV     [BX],AX
  56.           POP     DS
  57.                   POP     BP
  58.           RET     16
  59.  
  60. GETCOORDS ENDP
  61.  
  62. SETCOORDS PROC    FAR   ;void pascal far setcoords(int topx,int topy,
  63.                         ;                          int botx,int boty);
  64.  
  65. ; set window coordinates (0 based)
  66.  
  67.           PUSH    BP
  68.           MOV     BP,SP
  69.           MOV     AH,[BP]+12
  70.           MOV     _atopx,AH
  71.           MOV     AH,[BP]+10
  72.           MOV     _atopy,AH
  73.           MOV     AH,[BP]+8
  74.           MOV     _abotx,AH
  75.           MOV     AH,[BP]+6
  76.           MOV     _aboty,AH
  77.           POP     BP
  78.           RET     8
  79.  
  80. SETCOORDS ENDP
  81.  
  82.  
  83.  
  84. SETFASTANSI PROC    FAR   ;void pascal far setfastansi(int fast);
  85.  
  86. ; set fast ansi (0 = off, ffh = BIOS)
  87.  
  88.           PUSH    BP
  89.           MOV     BP,SP
  90.           MOV     AH,[BP]+6
  91.           MOV     _fastansiout,AH
  92.           POP     BP
  93.           RET     2
  94.  
  95. SETFASTANSI ENDP
  96.  
  97.  
  98.  
  99. GETFASTANSI PROC    FAR   ;int pascal far getfastansi(void);
  100.  
  101. ; get fast ansi setting (0 = off)
  102.  
  103.           XOR     AX,AX
  104.           MOV     AH,_fastansiout
  105.           RET
  106.  
  107. GETFASTANSI ENDP
  108.  
  109.  
  110.  
  111. ANSI      PROC    FAR   ;int pascal far ansi(char far *str);
  112.  
  113. ; display a string through DOS' ANSI driver, respecting a window
  114.  
  115.           PUSH    BP                    ;set up stack frame
  116.           MOV     BP,SP
  117.  
  118.           PUSH    DS                    ;save ds
  119.  
  120.           MOV     AH,15                 ;get current video state
  121.           INT     10H
  122.           MOV     VID_PAGE,BH           ;save it
  123.  
  124.           MOV     BX,[BP]+6             ;get string address
  125.           MOV     DS,[BP]+8             ;set ds
  126.           PUSH    BX                    ;save original address
  127.           MOV     CX,BX
  128.           XOR     AX,AX
  129.  
  130. ALOOP:
  131.           CALL    DOCHECKPOS
  132.           MOV     AL,[BX]               ;set al to char to print
  133.           CMP     AL,10                 ;\n?
  134.           JNZ     CHKCR                 ;no
  135.           MOV     DX,AX
  136.           MOV     AH,2
  137.           INT     21H                   ;display it
  138.           CALL    DOCHECKPOS
  139.           MOV     AL,13                 ;and do cr
  140.           JMP     NOEXIT1
  141. CHKCR:
  142.           CMP     AL,13                 ;\r?
  143.           JNZ     CHKANSI               ;no
  144.           MOV     DX,AX
  145.           MOV     AH,2
  146.           INT     21H                   ;display it
  147.           CALL    DOCHECKPOS
  148.           MOV     AL,10                 ;and do lf
  149.           JMP     NOEXIT1
  150. CHKANSI:
  151.           CMP     AL,27                 ;escape?
  152.           JNZ     GOON                  ;no, skip all this...
  153.           CMP     BYTE PTR [BX]+1,'['   ; check for various ansi
  154.           JNZ     GOON                  ; commands that would screw
  155.           CMP     BYTE PTR [BX]+2,'2'   ; up our window
  156.           JNZ     GOON1                 ; \x1b[2J
  157.           CMP     BYTE PTR [BX]+3,'J'
  158.           JNZ     GOON2
  159.           ADD     BX,4
  160.           CALL    CLEARSCRN
  161.           JMP     SHORT ALOOP
  162. GOON1:
  163.           CMP     BYTE PTR [BX]+2,'K'   ; \x1b[K
  164.           JNZ     GOON3
  165.           ADD     BX,3
  166.           CALL    CLEARLINE
  167.           JMP     SHORT ALOOP
  168. GOON3:
  169.           CMP     BYTE PTR [BX]+2,'k'   ;\x1b[k
  170.           JNZ     GOON
  171.           ADD     BX,3
  172.           CALL    CLEAREOL
  173.           JMP     SHORT ALOOP
  174. GOON2:
  175.           CMP     BYTE PTR [BX]+3,'j'   ;\x1b[2j
  176.           JNZ     GOON
  177.           ADD     BX,4
  178.           CALL    CLEAREOS
  179.           JMP     ALOOP
  180. GOON:
  181.           CMP     AL,0              ;End of string?
  182.           JNZ     NOEXIT1
  183.           JMP     SHORT EXIT1
  184. NOEXIT1:                            
  185.           CMP     _fastansiout,0    ;fast ansi writes?
  186.           JZ      BIOSWRITES        ;nope
  187.           INT     29H
  188.           JMP     SHORT SKIPSLOW
  189. BIOSWRITES:
  190.           CMP     _fastansiout,255  ;bios writes?
  191.           JZ      SLOWWRITES        ;nope
  192.           PUSH    BX
  193.           PUSH    CX
  194.           MOV     BH,VID_PAGE
  195.           INT     10H
  196.           POP     CX
  197.           POP     BX
  198.           JMP     SHORT SKIPSLOW
  199. SLOWWRITES:
  200.           MOV     DX,AX
  201.           MOV     AH,2
  202.           INT     21H               ;display it
  203. SKIPSLOW:
  204.           INC     BX
  205.           CMP     BYTE PTR [BX],0   ;end of string?
  206.           JZ      EXIT1             ;yep
  207.           CMP     BX,CX             ;string too long?
  208.           JZ      EXIT1             ;yep, it wrapped; avoid crash
  209.           JMP     ALOOP             ;nope
  210. EXIT1:                              ;wrap it up...
  211.           CALL    DOCHECKPOS
  212.           POP     AX                ;retrieve old start pos
  213.           SUB     BX,AX             ;subtract from current pos
  214.           MOV     AX,BX             ;return length of string printed
  215.  
  216.           POP     DS
  217.           POP     BP
  218.           RET     4
  219.  
  220. ANSI      ENDP
  221.  
  222.  
  223.  
  224. DOCHECKPOS:                         ;check cursor pos, protect window
  225.           PUSH    AX                ;Save the registers that will be affected
  226.           PUSH    BX
  227.           PUSH    CX
  228.           PUSH    DX
  229.           CALL    WHERE_ARE_WE      ; where the cursor is.......
  230. CHECKTOPX:
  231.           CMP     DL,_atopx
  232.           JGE     CHECKBOTX
  233.           MOV     AH,2
  234.           MOV     DL,_atopx
  235.           MOV     BH,VID_PAGE
  236.           INT     10H
  237.           JMP     SHORT CHECKTOPY
  238. CHECKBOTX:
  239.           CMP     DL,_abotx
  240.           JLE     CHECKTOPY
  241.           MOV     DL,_atopx
  242.           INC     DH
  243.           MOV     AH,2
  244.           MOV     BH,VID_PAGE
  245.           INT     10H
  246. CHECKTOPY:
  247.           CMP     DH,_atopy
  248.           JGE     CHECKBOTY
  249.           MOV     AH,2
  250.           MOV     DH,_atopy
  251.           MOV     BH,VID_PAGE
  252.           INT     10H
  253.           JMP     SHORT OUTTAHERE
  254. CHECKBOTY:
  255.           CMP     DH,_aboty         ; Row ???
  256.           JLE     OUTTAHERE         ; Jump if less
  257.           CALL    SCROLLIT          ; else scroll, we're too low
  258.           MOV     DH,_aboty         ; put cursor back in window
  259.           MOV     BH,VID_PAGE
  260.           INT     10H
  261. OUTTAHERE:
  262.           POP     DX                ;Restore registers
  263.           POP     CX
  264.           POP     BX
  265.           POP     AX
  266.           RET
  267.  
  268.  
  269. WHERE_ARE_WE:                       ;Get the current cursor position
  270.           PUSH    AX                ;Save the registers
  271.           PUSH    BX
  272.           PUSH    CX
  273.           MOV     AH,03             ;SET UP FOR ROM-BIOS CALL (03H)
  274.           MOV     BH,VID_PAGE       ;TO READ THE CURRENT CURSOR POSITION
  275.           INT     10H               ; DH = ROW   DL = COLUMN
  276.           POP     CX                ;Restore the registers
  277.           POP     BX
  278.           POP     AX
  279.           RET                        ;And go back from wence we came
  280.  
  281.  
  282. SCROLLIT: PUSH    AX                ;Save the registers that will be affected
  283.           PUSH    BX
  284.           PUSH    CX
  285.           PUSH    DX
  286.           MOV     AH,2              ;Now set cursor position to ???,???
  287.           MOV     DH,_aboty
  288.           MOV     DL,_atopx
  289.           MOV     BH,VID_PAGE       ;attribute
  290.           INT     10H
  291.           MOV     AH,8              ;Get the current character attribute
  292.           MOV     BH,VID_PAGE
  293.           INT     10H
  294.           MOV     BH,AH             ;Transfer the attribute to BH for next call
  295.           MOV     AH,6              ;Otherwise scroll ??? lines
  296.           MOV     AL,1              ;Only blank line ???
  297.           MOV     CH,_atopy
  298.           MOV     CL,_atopx
  299.           MOV     DH,_aboty
  300.           MOV     DL,_abotx
  301.           INT     10H               ;And do it.......
  302.           MOV     AH,2              ;Now set cursor position to ???,???
  303.           MOV     DH,_aboty
  304.           MOV     DL,_atopx
  305.           MOV     BH,VID_PAGE
  306.           INT     10H
  307.           POP     DX                ;Restore the stack like it was
  308.           POP     CX
  309.           POP     BX
  310.           POP     AX
  311.           RET
  312.  
  313. CLEARSCRN:                          ;Clear current window
  314.           PUSH    AX                ;Save the registers
  315.           PUSH    BX
  316.           PUSH    CX
  317.           PUSH    DX
  318.           MOV     AH,2              ;Now set cursor position to ???,???
  319.           MOV     DH,_aboty
  320.           MOV     DL,_atopx
  321.           MOV     BH,VID_PAGE       ;attribute
  322.           INT     10H
  323. ;          MOV     AH,8              ;Get the current character attribute
  324. ;          MOV     BH,VID_PAGE
  325. ;          INT     10H
  326. ;          MOV     BH,AH             ;Transfer the attribute to BH for next call
  327.           MOV     BH,7
  328.           MOV     AH,6              ;Otherwise scroll ??? lines
  329.           MOV     AL,0              ;clear screen
  330.           MOV     CH,_atopy
  331.           MOV     CL,_atopx
  332.           MOV     DH,_aboty
  333.           MOV     DL,_abotx
  334.           INT     10H               ;And do it.......
  335.           MOV     AH,2              ;Now set cursor position to ???,???
  336.           MOV     DH,_atopy
  337.           MOV     DL,_atopx
  338.           MOV     BH,VID_PAGE
  339.           INT     10H
  340.           POP     DX                ;Restore the stack like it was
  341.           POP     CX
  342.           POP     BX
  343.           POP     AX
  344.           RET
  345.  
  346. CLEAREOS:                           ;Clear to end of current window
  347.           PUSH    AX                ;Save the registers
  348.           PUSH    BX
  349.           PUSH    CX
  350.           PUSH    DX
  351.           MOV     AH,8              ;Get the current character attribute
  352.           MOV     BH,VID_PAGE
  353.           INT     10H
  354.           MOV     BH,AH             ;Transfer the attribute to BH for next call
  355.           MOV     AH,6              ;Otherwise scroll ??? lines
  356.           MOV     AL,0              ;clear
  357.           CALL    WHERE_ARE_WE
  358.           PUSH    DX                ;save it
  359.           MOV     CX,DX
  360.           MOV     DH,_aboty
  361.           MOV     DL,_abotx
  362.           INT     10H               ;And do it.......
  363.           MOV     AH,2
  364.           MOV     BH,VID_PAGE
  365.           POP     DX
  366.           INT     10H               ;restore position
  367.           POP     DX                ;Restore the stack like it was
  368.           POP     CX
  369.           POP     BX
  370.           POP     AX
  371.           RET
  372.  
  373. CLEARLINE:                          ;Clear current line
  374.           PUSH    AX                ;Save the registers
  375.           PUSH    BX
  376.           PUSH    CX
  377.           PUSH    DX
  378.           MOV     AH,8              ;Get the current character attribute
  379.           MOV     BH,VID_PAGE
  380.           INT     10H
  381.           CALL    WHERE_ARE_WE
  382.           PUSH    DX                ;save it
  383.           MOV     BH,AH             ;Transfer the attribute to BH for next call
  384.           MOV     AH,6              ;Otherwise scroll ??? lines
  385.           MOV     AL,0              ; clear line
  386.           MOV     CX,DX
  387.           MOV     CL,_atopx
  388.           MOV     DL,_abotx
  389.           INT     10H               ; And do it.......
  390.           MOV     AH,2              ;Now set cursor position to ???,???
  391.           MOV     DL,_atopx
  392.           MOV     BH,VID_PAGE
  393.           INT     10H
  394.           MOV     AH,2
  395.           MOV     BH,VID_PAGE
  396.           POP     DX
  397.           INT     10H               ;restore position
  398.           POP     DX                ;Restore the stack like it was
  399.           POP     CX
  400.           POP     BX
  401.           POP     AX
  402.           RET
  403.  
  404. CLEAREOL:                           ;Clear to end of current line
  405.           PUSH    AX                ;Save the registers
  406.           PUSH    BX
  407.           PUSH    CX
  408.           PUSH    DX
  409.           MOV     AH,8              ;Get the current character attribute
  410.           MOV     BH,VID_PAGE
  411.           INT     10H
  412.           CALL    WHERE_ARE_WE
  413.           PUSH    DX                ;save it
  414.           MOV     BH,AH             ;Transfer the attribute to BH for next call
  415.           MOV     AH,6              ;Otherwise scroll ??? lines
  416.           MOV     AL,0              ;clear line
  417.           MOV     CX,DX
  418.           MOV     DL,_abotx
  419.           INT     10H               ;And do it.......
  420.           MOV     AH,2
  421.           MOV     BH,VID_PAGE
  422.           POP     DX
  423.           INT     10H               ;restore position
  424.           POP     DX                ;Restore the stack like it was
  425.           POP     CX
  426.           POP     BX
  427.           POP     AX
  428.           RET
  429.  
  430. ANSI_PRNT ENDS
  431.           END
  432.